<template>
  <div class="reports-wrapper">
    <!-- 面包屑导航 -->
    <bread/>
    <!-- 卡片视图区域 -->
    <el-card>
      <!-- 2. 准备一个容器 -->
      <div id="main" style="width: 750px; height: 400px"></div>
    </el-card>
  </div>
</template>

<script>
import reportApi from "..//../api/report";

// 1. 引入echarts
const echarts = require("echarts");
import _ from 'lodash';
import bread from '../bread.vue'
export default {
  components:{bread},
  data() {
    return {
      // 4. 指定图表的配置项和数据
      option: {
        title: {
          text: "用户来源",
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#E9EEF3",
            },
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            boundaryGap: false,
          },
        ],
        yAxis: [
          {
            type: "value",
          },
        ],
      }
    }
  },
  async mounted() {
    // 当DOM元素加载完毕以后
    // console.log(echarts)
    // 3. 基于准备好的dom，初始化echarts实例
    const myChart = echarts.init(document.getElementById("main"));
    // const res = await this.$http.get('reports/type/1');
    const res = await reportApi.mounted();
    const { data, meta } = res.data;
    if(meta.status !== 200) {
      this.$message.error(meta.msg)
    } else {
      // 合并对象
      // const obj = Object.assign(data, this.option);
      const obj = _.merge(data, this.option);
      myChart.setOption(obj);
    }
  },
};
</script>

<style lang="scss" scoped>
.el-card {
  margin-top: 15px;
}
</style>